package COSC455Compiler;

import java.util.Stack;

public class ParseTrees {

    public static void Pusher(String currentSymbol) {
        switch (currentSymbol.toUpperCase()) {
            case LexicalTokens.Head_Begin: //OIC
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Paragraph_Begin: //OIC 
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.List_Begin: //OIC
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Title_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Bold_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Italics_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Item_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Audio_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Video_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Variable_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
            case LexicalTokens.Visible_Begin: //MKAY
                MyCompiler.symbolStack.push(currentSymbol);
                break;
        }
    }

    public static String getTag(String tag) {
        String ClosingTag = "";
        if (MyCompiler.symbolStack.size() > 0) {
            if (LexicalTokens.Head_END.equalsIgnoreCase(tag)) {
                if (LexicalTokens.Head_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Head Found so close will be </Head>
                    ClosingTag = "</head>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Paragraph_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Paragraph Found so close will be </p>
                    ClosingTag = "</p>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.List_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //List Found so close will be </ul>
                    ClosingTag = "</ul>";
                    MyCompiler.symbolStack.pop();
                }
            } else if (LexicalTokens.Title_END.equalsIgnoreCase(tag)) {
                if (LexicalTokens.Title_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Title Found so close will be </title>
                    ClosingTag = "</title>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Bold_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Bold Found so close will be </b>
                    ClosingTag = "</b>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Italics_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Italics Found so close will be </i>
                    ClosingTag = "</i>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Item_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Item Found so close will be </li>
                    ClosingTag = "</li>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Audio_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Audio Found so close will be </audio>
                    ClosingTag = "\"></audio>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Video_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Video Found so close will be />
                    ClosingTag = "\"/>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Variable_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Variable Found so close will be </var>
                    ClosingTag = "</var>";
                    MyCompiler.symbolStack.pop();
                } else if (LexicalTokens.Visible_Begin.equalsIgnoreCase(MyCompiler.symbolStack.peek())) {
                    //Visible Found
                    MyCompiler.symbolStack.pop();
                }
            }
        }
        return ClosingTag;
    }
}